const TOKEN_NAME = 'token'

// 获取 token
const getUserinfo = (NAME = TOKEN_NAME) => {
  const str = localStorage.getItem(NAME)
  return JSON.parse(str)
}

// 设置 token
const setUserinfo = (VALUE, NAME = TOKEN_NAME) => {
  const str = JSON.stringify(VALUE)
  localStorage.setItem(NAME, str)
}

// 删除 token
const removeUserinfo = (NAME = TOKEN_NAME) => localStorage.removeItem(NAME)

// 是否登录（有权限）
const isAuth = () => !!getUserinfo()

export { getUserinfo, setUserinfo, removeUserinfo, isAuth }
